package net.csdra.libraryborrowing.service;

import net.csdra.libraryborrowing.domain.Address;
import net.csdra.libraryborrowing.domain.AddressRepository;
import net.csdra.libraryborrowing.service.user.CurrentUserInfo;
import net.csdra.libraryborrowing.util.Utils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import java.nio.file.AccessDeniedException;

/**
 * Created by xiaomi on 2017/10/17.
 */
@Service
public class AddressManageServiceImpl implements AddressManageService {

    @Autowired
    AddressRepository addressRepository;
    @Autowired
    CurrentUserInfo currentUserInfo;


    @Override
    public Address createAddress(CreateAddress createAddress) throws AccessDeniedException {
        Address address = Utils.createAutoSet(Address.class, currentUserInfo.get().getUserName());
        Utils.copy(createAddress, address);
        addressRepository.save(address);
        Address returnValue = new Address();
        BeanUtils.copyProperties(address, returnValue);
        return returnValue;
    }

    @Override
    public Address updateAddress(UpdateAddress updateAddress) {
        Address address = addressRepository.findOne(updateAddress.getAddressId());
        Assert.notNull(address,"@！");
        return null;
    }
}
